/*
 *  PPDataStructures.h
 *  PigeonsFoundation
 *
 *  Created by Jacob Basham on 1/13/07.
 *  Copyright 2007, PaperPigeons.net
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without 
 *  modification, are permitted provided that the following conditions 
 *  are met:
 *  1. Redistributions of source code must retain the above copyright 
 *     notice, this list of conditions and the following disclaimer.
 *	2. Redistributions in binary form must reproduce the above copyright 
 *	   notice, this list of conditions and the following disclaimer in 
 *	   the documentation and/or other materials provided with the distribution.
 *	3. Neither the name of PaperPigeons.net nor the names of its contributors 
 *	   may be used to endorse or promote products derived from this software 
 *	   without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 *	"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 *	LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 *	FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
 *	COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
 *	INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 *	BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 *	CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
 *	LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
 *	IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 *	POSSIBILITY OF SUCH DAMAGE.
 */

#import <Foundation/Foundation.h>
#import <sys/queue.h>

/*!
    @class
    @abstract   Base object for BSD linked list data structures.
    @discussion  Uses BSD's queue header to create ObjectiveC queues and stacks.
*/

@interface PPBasicStructure : NSObject 
{
	struct Object {
		id object;
		LIST_ENTRY(Object) objects;
	} * internalObject;

	int structSize;
	LIST_HEAD(ObjectsHead, Object) objectsHead;
}

/*!
    @method     
    @abstract   Initializes base structure object.
    @discussion Initializes base linked list object with queue.h
	@result Stack or Queue object.
*/
- (id)init;

/*!
    @method     
    @abstract   Initializes base structure object.
    @discussion Initializes base linked list object with queue.h
	@param array Array of objects to add to structure.
	@result Stack or Queue object
*/
- (id)initWithArray:(NSArray *)array;

/*!
    @method     
    @abstract   Adds an object to the Stack or Queue.
    @discussion Adds an object to the Stack or Queue.
	@param object Object to add to Stack or Queue.
*/
- (void)addObject:(id)object;

/*!
    @method     
    @abstract   Adds an array to the Stack or Queue.
    @discussion Adds an array to the Stack or Queue.
	@param array Array of objects to add to Stack or Queue.
*/
- (void)addArray:(NSArray *)array;

/*!
    @method     
    @abstract   Returns the next object in the structure.
    @discussion Returns the next object in the structure.
	@result	next object in the structure.
*/
- (id)nextObject;

/*!
    @method     
    @abstract   Returns an array of objects in the structure.
    @discussion Returns an array of objects in the structure.
	@result Array of the objects in the structure.
*/
- (id)objects;

/*!
    @method     
    @abstract   Deallocation of the structure.
    @discussion Deallocation of the structure.
*/
- (void)dealloc;

@end

/*!
    @class
    @abstract   Basic Stack class.
    @discussion  ObjectiveC Stack class
*/

@interface PPStack : PPBasicStructure 
{
}

/*!
    @method     
    @abstract   Creates and returns a stack.
    @discussion Creates and returns a stack.
	@result A new stack object.
*/
+ (id)stack;

/*!
    @method     
    @abstract   Adds an array of objects to the stack.
    @discussion Adds an array of objects to the stack.
	@param array Array of objects to add to the stack.
	@result A new stack initialized with objects in array.
*/
+ (id)stackWithArray:(NSArray *)array;

/*!
    @method     
    @abstract   Add object to the stack.
    @discussion Adds an ObjectiveC object to the stack.
	@param object Object to add to the stack.
*/
- (void)addObject:(id)object;

@end

/*!
    @class
    @abstract   Basic Queue class.
    @discussion  ObjectiveC Queue class
*/

@interface PPQueue : PPBasicStructure 
{
	struct Object * lastObject;
}

/*!
    @method     
    @abstract   Creates and returns a queue.
    @discussion Creates and returns a queue.
	@result A new queue object.
*/
+ (id)queue;

/*!
    @method     
    @abstract   Adds an array of objects to the queue.
    @discussion Adds an array of objects to the queue.
	@param array Array of objects to add to the queue.
	@result A new queue initialized with objects in array.
*/
+ (id)queueWithArray:(NSArray *)array;

/*!
    @method     
    @abstract   Add object to the queue.
    @discussion Adds an ObjectiveC object to the queue.
	@param object Object to add to the queue.
*/
- (void)addObject:(id)object;

@end
